home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Amiga Public Domain Connection / APDC Disk #005 - Amiga Basic Programs (198x)(Amiga Public Domain Connection)(US)[WB].zip / APDC Disk #005 - Amiga Basic Programs (198x)(Amiga Public Domain Connection)(US)[WB].adf / Stairs (.txt) < prev    next >
AmigaBASIC Source Code  |  1988-03-13  |  5KB  |  243 lines

  1. '
  2. 'Magic Staircase by Gary Cuba (803)776-5295 -- developed
  3. '    1/31/86. All copyrights waived, but mention the author!
  4. '
  5. 'Will the tones ever stop ascending?
  6. '
  7. 'This is a musical illusion based upon perceptual circularity
  8. '    of widely space tones whose volumes are defined as a
  9. '    sinesoidal relationship TO their frequency.
  10. 'There are 4 tones spaced an octave apart. each tone advances
  11. '    in frequency by one half-note until it is within 1/2
  12. '    note of the NEXT octave. at this POINT it starts over
  13. '    again at its beginning frequency. 
  14. 'Each tone's volume is set according to its position along a
  15. '    sinewave. 
  16. 'See Roger N. Shepard, 'Circularity in Judgements of Relative
  17. '    Pitch', The Journal of the Acoustical Society of America,
  18. '    (December 1964).
  19. '
  20.  
  21. setup:
  22.  
  23.    OPTION BASE 1
  24.    GOSUB initialize
  25.    GOSUB getpoints
  26.    RESTORE
  27.    k=1
  28.    nw=9
  29.    
  30. mainloop:
  31.        
  32.    FOR pause =1 TO 2000
  33.       NEXT   
  34.    FOR j=1 TO 4      
  35.       SOUND f(j,k),20,v(j,k),j-1
  36.       NEXT 
  37.    k=k+1
  38.       IF k>12 THEN k=1
  39.  
  40.   IF st=0 THEN
  41.     GOTO continue
  42.     END IF
  43.     
  44.   FOR i=1 TO 6
  45.     AREA(x%(poly(old,i)),y%(poly(old,i)))
  46.     NEXT i
  47.     AREAFILL 1
  48.  
  49. continue:
  50.     
  51.   FOR i=1 TO 6
  52.     AREA (x%(poly(nw,i)),y%(poly(nw,i)))
  53.     NEXT i
  54.     AREAFILL 1
  55.     
  56.   old=nw
  57.   nw=nw+1
  58.   IF nw >24 THEN
  59.     nw=9      
  60.   END IF
  61.   FOR pause=1 TO 500
  62.     NEXT pause
  63.   st=1  
  64.   GOTO mainloop  
  65.   
  66. initialize:
  67.  
  68.    DIM f(4,12)  'set f(voice,tone #) as frequency 
  69.    DIM v(4,12)  'set v(voice,tone #) as volume
  70.          
  71.    'these are the frequency steps FOR each voice:
  72.    key=0.2
  73.    DATA 130.81,138.59,146.83,155.56,164.81,174.61
  74.    DATA 185,196,207.65,220,233.08,246.94
  75.    DATA 261.63,277.18,293.66,311.13,329.63,349.23
  76.    DATA 369.99,392,415.3,440,466.16,493.88
  77.    DATA 523.25,554.37,587.33,622.25,659.26,698.46
  78.    DATA 739.99,783.99,830.61,880,932.33,977.7
  79.    DATA 1046.5,1108.7,1174.7,1244.5,1318.5,1396.9
  80.    DATA 1480,1568,1661.2,1760,1864.7,1975.5
  81.    FOR i= 1 TO 4
  82.       FOR j=1 TO 12
  83.          READ f(i,j)
  84.          f(i,j)=f(i,j)*key    'lower them a little bit
  85.          NEXT
  86.       NEXT
  87.  
  88.    'pi defines the length of the volume sinewave (only 1/2
  89.    'of a waveform is used).
  90.    'inc is the stepping increment for the tone volumes.
  91.    'the 240 multiplier supplies sufficient maximum volume.
  92.    pi=3.14159: inc=pi/48
  93.  
  94.    ct=0  'voice 1 volumes
  95.    FOR i=0 TO pi/4-inc STEP inc
  96.       ct=ct+1
  97.       v(1,ct)=INT(240*SIN(i))
  98.       NEXT
  99.    ct=0  'voice 2 volumes
  100.    FOR i=pi/4 TO pi/2-inc STEP inc
  101.       ct=ct+1
  102.       v(2,ct)=INT(240*SIN(i))
  103.       NEXT
  104.    ct=0  'voice 3 volumes
  105.    FOR i=pi/2 TO ((3*pi)/4)-inc STEP inc
  106.       ct=ct+1
  107.       v(3,ct)=INT(240*SIN(i))
  108.       NEXT
  109.    ct=0  'voice 4 volumes
  110.    FOR i=(3*pi)/4 TO pi-inc STEP inc
  111.       ct=ct+1
  112.       v(4,ct)=INT(240*SIN(i))
  113.       NEXT
  114.  
  115. 'the sound waveforms (disk file):
  116.    DIM timbre%(256)
  117.    OPEN "tone1" FOR INPUT AS #1
  118.    FOR k=1 TO 256
  119.       INPUT #1,timbre%(k)
  120.       NEXT k
  121.    CLOSE #1
  122.    
  123.    WAVE 0,timbre%
  124.    WAVE 1,timbre%
  125.    WAVE 2,timbre%
  126.    WAVE 3,timbre%
  127.     
  128. RETURN
  129.  
  130. getpoints:    'picture stuff
  131.  
  132.   DIM poly(24,16)
  133.   DIM x%(68)
  134.   DIM y%(68)
  135.   DIM x(68)
  136.   DIM y(68)
  137.   
  138.   DATA 10,120,10,45,25,55,25,50,40,60,40,55,55,65,55,60
  139.   DATA 70,70,70,65,85,75,85,70,100,80,100,75,115,85,115,190
  140.   DATA 160,160,160,45,145,54,145,60,130,70,130,75,115,66
  141.   DATA 115,60,130,50,130,45,145,35,145,30,130,39,115,30
  142.   DATA 130,21,130,15,115,25,115,20,100,30,100,25,85,35
  143.   DATA 85,30,70,40,70,35,55,45,55,40,47.5,45,40,40,52,47.5
  144.   DATA 55,45,67,52.5,70,50,82,57.5,85,55,97,62.5,100,60
  145.   DATA 112,67.5,35,42.5,25,35,29,37.5,40,30,43,32.5,55,25
  146.   DATA 58,27.5,70,20,74,22.5,85,15,88,17.5,100,10,103,12.5,115,5
  147.   
  148.   
  149.   FOR i=1 TO 67
  150.     READ x(i),y(i)
  151.     x%(i)=(x(i)+50)*2.5
  152.     y%(i)=y(i)*0.9
  153.     NEXT i    
  154.   
  155.   DATA 1,2,3,4,5,6,7,8,9,16
  156.     FOR i=1 TO 10    
  157.       READ poly(1,i)
  158.       AREA (x%(poly(1,i)),y%(poly(1,i)))
  159.       NEXT i
  160.     AREAFILL 
  161.   
  162.   DATA 9,10,11,12,13,14,15,16
  163.     FOR i=1 TO 8
  164.       READ poly(2,i)
  165.       AREA (x%(poly(2,i)),y%(poly(2,i)))
  166.       NEXT i
  167.       AREAFILL
  168.       
  169.   DATA 23,24,21,22
  170.     FOR i=1 TO 4
  171.       READ poly(3,i)
  172.       AREA (x%(poly(3,i)),y%(poly(3,i)))
  173.       NEXT i
  174.       AREAFILL
  175.       
  176.   DATA 24,25,20,19,26,29,30
  177.     FOR i=1 TO 7
  178.       READ poly(4,i)
  179.       AREA (x%(poly(4,i)),y%(poly(4,i)))
  180.       NEXT i
  181.       AREAFILL
  182.       
  183.   COLOR 3    
  184.   DATA 37,38,39,40,41,42,43,45,46,47,48,49,50,51,52
  185.     FOR i=1 TO 15
  186.       READ poly(5,i)
  187.       AREA (x%(poly(5,i)),y%(poly(5,i)))
  188.       NEXT i
  189.       AREAFILL
  190.       
  191.   DATA 37,36,35,34,33,32,31,30,23,53,52
  192.     FOR i=1 TO 11
  193.       READ poly(6,i)
  194.       AREA (x%(poly(6,i)),y%(poly(6,i)))
  195.       NEXT i
  196.       AREAFILL            
  197.   
  198.   DATA 26,27,28,29
  199.     FOR i=1 TO 4
  200.       READ poly(7,i)
  201.       AREA (x%(poly(7,i)),y%(poly(7,i)))
  202.       NEXT i
  203.       AREAFILL
  204.       
  205.   DATA 15,16,17,18,19,20,21,22
  206.     FOR i=1 TO 8
  207.       READ poly(8,i)
  208.       AREA (x%(poly(8,i)),y%(poly(8,i)))
  209.       NEXT i
  210.       AREAFILL    
  211.   
  212.   COLOR 2
  213.   DATA 2,3,4,54,55,55,4,44,45,6,5,5,6,46,47,8,7,7
  214.   DATA 8,48,49,10,9,9,10,50,51,12,11,11,12,52,53,14,13,13
  215.   DATA 14,23,22,15,15,15,20,21,24,25,25,25,18,19,26,27,27,27
  216.   DATA 28,29,30,31,31,31,32,33,34,66,67,67,34,35,36,64,65,65
  217.   DATA 36,37,38,62,63,63,38,39,40,60,61,61
  218.   DATA 40,41,42,58,59,59,42,43,44,54,56,57
  219.   FOR i=9 TO 24
  220.     FOR j=1 TO 6
  221.       READ poly(i,j)
  222.       AREA (x%(poly(i,j)),y%(poly(i,j)))
  223.       NEXT j
  224.     AREAFILL
  225.     NEXT i
  226.  
  227.   COLOR 1
  228.   LOCATE 1,1
  229.   PRINT "A polyperceptual illusion"
  230.   LOCATE 2,3
  231.   PRINT "...by Gary Cuba"
  232.   LOCATE 16,5
  233.   PRINT "Will the tones ever"
  234.   LOCATE 17,7
  235.   PRINT "stop ascending?"
  236.   LOCATE 19,12
  237.   PRINT "Where do the steps lead?"
  238.   
  239. RETURN
  240.   
  241.   
  242.         
  243.